import re
import logging
from odoo import fields, api, models, tools, _
from odoo.exceptions import UserError, ValidationError

_logger = logging.getLogger(__name__)

class RespondentUnit(models.Model):
    _name = 'respondent.unit'
    _description = 'Respondent Unit'

    Selection = [('koyo_factory', '库有本厂'), ('koyo_external_warehouse', '库有外仓'), ('others', '其它')]
    unit_name = fields.Selection(Selection, string='单位名称', required=True)
    respondent_unit_address_ids = fields.One2many('respondent.address', 'respondent_unit_id', string='单位地址')
    name = fields.Char(compute='_compute_name')

    def _compute_name(self):
        for rec in self:
            if rec.unit_name == 'koyo_factory':
                rec.name = '库有本厂'
            elif rec.unit_name == 'koyo_external_warehouse':
                rec.name = '库有外仓'
            else:
                rec.name = '其他'




